package com.pvdnc.tapkit.chat.chat.client;

import com.pvdnc.encrypt.RSA;
import com.pvdnc.encrypt.RSAKey;

import java.util.HashMap;
import java.util.Map;

public class KeyManager {
    private final Map<String,byte[]> mClientKeyMap=new HashMap<>();

    public final RSAKey mSelfKey=new RSAKey(2048);

    public byte[] decrypt(byte[] data){
        return RSA.decrypt(data,mSelfKey.getPrivateKey());
    }

    public void putKey(String name,byte[] publicKey){
        mClientKeyMap.put(name,publicKey);
    }

    public byte[] getKey(String name){
        return mClientKeyMap.get(name);
    }

    public byte[] encrypt(String toName,byte[] data){
        byte[] publicKey=getKey(toName);
        return RSA.encrypt(data,RSAKey.getPublicKey(publicKey));
    }
}
